package cn.zglbk.generator.utils;

import org.apache.commons.lang.WordUtils;

/**
 * @author zglbk.cn
 * @email 1030681978@qq.com
 * @date 2020/10/21 21:28
 */
public class StringUtils {

    /**
     * 列名转换成Java属性名
     * 去掉"_"符号并将首字母大写和将"_"符号后面的首字母大写
     * attr_name => AttrName
     */
    public static String columnToJava(String columnName) {
        return WordUtils.capitalizeFully(columnName, new char[]{'_'}).replace("_", "");
    }
    /**
     * 表名转换成Java类名
     */
    public static String tableToJava(String tableName, String[] tablePrefixArray) {
        if (null != tablePrefixArray && tablePrefixArray.length > 0) {
            for (String tablePrefix : tablePrefixArray) {
                if (tableName.startsWith(tablePrefix)){
                    tableName = tableName.replaceFirst(tablePrefix, "");
                }
            }
        }
        return columnToJava(tableName);
    }
}
